package models

import (
	"fmt"
	"github.com/astaxie/beego/orm"
)

type Settings struct {
	Id    int64  `orm:"pk;auto"`
	Proxy string `orm:"size(50)"`
	Area  string `orm:"size(50)"`
}

func init() {
	orm.RegisterModel(new(Settings))
}

// UpdateApis updates  by Id and returns error if
// the record to be updated doesn't exist
func (s *Settings) UpdateApisById() (err error) {
	o := orm.NewOrm()
	v := Settings{Id: s.Id}
	// ascertain id exists in the database
	if err = o.Read(&v); err == nil {
		if num, err := o.Update(s); err == nil {
			fmt.Println("Number of records updated in database:", num)
		}
	}
	return
}
func (s *Settings) GetById() (err error) {
	o := orm.NewOrm()

	err = o.Read(s)
	return
}
